﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Data;
using DBA.Data.ADO;
using DBA.Bll;

namespace DBA.Web.StudentManage
{
    public partial class StudentStudyList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            hdEmpID.Value = Request.Params["id"];
            Bind(1, null);
        }



        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("Country", txtCountry.Text.Trim());
            dict.Add("School", txtSchool.Text.Trim());
            dict.Add("Type", txtType.Text.Trim());

            ViewState["conditions"] = dict;
            Bind(1, dict);
        }



        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IDictionary<String, String> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IDictionary<String, String>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, dict);
        }

        private void Bind(int pageIdx, IDictionary<String, String> dict)
        {

            string sql = "select * from Em_Study where usertype=2 and UserID=@UserID ";
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            dal.ManagerParameter.ClearParameter();
            dal.ManagerParameter.AddNewInParameter("UserID", hdEmpID.Value);
            if (dict != null)
            {
                if (!dict["Country"].ToString().Equals(string.Empty))
                {
                    sql += " and Country like '%'+@Country+'%'";
                    dal.ManagerParameter.AddNewInParameter("Country", dict["Country"].ToString());
                }
                if (!dict["School"].ToString().Equals(string.Empty))
                {
                    sql += " and School like '%'+@School+'%'";
                    dal.ManagerParameter.AddNewInParameter("School", dict["School"].ToString());
                }
                if (!dict["Type"].ToString().Equals(string.Empty))
                {
                    sql += " and Type like '%'+@Type+'%'";
                    dal.ManagerParameter.AddNewInParameter("Type", dict["Type"].ToString());
                }

            }


            int iCount = 0;

            replData.DataSource = dal.ModifyData.GetPageDataTable("(" + sql + ")", "*", "", "id DESC", pageIdx, 10, ManagerSQL.PageViewTableType.MixtureTable, ref iCount);
            replData.DataBind();
            AspNetPager1.RecordCount = iCount;

        }

        protected void linkBtnMaskSearch_Click(object sender, EventArgs e)
        {
            //IDictionary<String, String> dict = new Dictionary<String, String>();
            //dict.Add("UserName", txtMaskMemberId.Text.Trim());
            //ViewState["conditions"] = dict;
            //Bind(1, dict);
        }

        protected void linkBtnDeleSelect_Click(object sender, EventArgs e)
        {
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            if (!String.IsNullOrEmpty(hidDeleString.Value))
            {
                string value = hidDeleString.Value;
                string sql = "delete from [Em_Study] where id in (" + value + ") and usertype=2;";
                dal.ExecuteNonQuery(sql);
                if (String.IsNullOrEmpty(dal.ErrorMessage))
                {
                    Bind(1, null);
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.correct('数据删除成功');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.error('数据删除失败');", true);
                }
            }
        }
    }
}